	 //webstock连接
    var userwebsocket = null;
    var onconnect=0;
    $(document).keyup(function(event){
    	  if(event.keyCode ==13){
    		  sendmsg();
    	  }
    	});
    
    $("#minichatwindow").hide();
    var headerSwiper = new Swiper('.swiper-container-head',{
        loop: true,
        autoplay: 10000,
        pagination : '.pagination',
        paginationClickable :true,
    }); 
    
    var headerSwiper = new Swiper('.swiper-container-comment',{
        loop: true,
        autoplay: 10000,
        pagination : '',
        paginationClickable :true,
    }); 
    
    function p(s) {
        return s < 10 ? '0' + s: s;
    }
    
    $("#openminichat").click(function(e){
    	//判断当前浏览器是否支持WebSocket
        if('WebSocket' in window){
        	if(onconnect==0){
        		userwebsocket = new WebSocket(url.webstockserver+param.webstockaddress);
                
                //连接发生错误的回调方法
                userwebsocket.onerror = function(event){
                	$(".GJshowmes").append("<div class='chatcontent' style='color:red'>在线咨询连接失败</div>");
                }
                 
                //连接成功建立的回调方法
                userwebsocket.onopen = function(event){
                	if(onconnect==0){
                		var nowdate=new Date();
                    	$(".GJshowmes").append("<div class='chatcontent' style='color:green'>在线咨询连接成功</div>");
                    	$(".GJshowmes").append("<div class='media'><div class='media-body'><div class='author-name-admin'><small class='chat-date'>"+p(nowdate.getHours())+":"+p(nowdate.getMinutes())+"</small>客服</div></br></div><a class='media-left' href='#'><img style='width:25px;height:25px' class='media-object' src='https://qiniu.cornergj.top/kefu.jpg'></a><div class='chat-message-admin'>您好，请问有什么能为您服务的？</br></div></div>");
                    	$(".GJshowmes").animate({scrollTop:($(".GJshowmes").height()+$(".GJshowmes").scrollTop())+'px'},500);
                    	onconnect=1;
                	}
                }
                 
                //接收到消息的回调方法
                userwebsocket.onmessage = function(event){
                    setMessageInnerHTML(event.data);
                }
                 
                //连接关闭的回调方法
                userwebsocket.onclose = function(){
                	$(".GJshowmes").append("<div class='chatcontent' style='color:red'>在线咨询连接关闭</div>");
                }
                 
                //监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
                window.onbeforeunload = function(){
                    userwebsocket.close();
                }
        	}
            $("#minichatwindow").slideToggle();
        }
        else{
            alert('对不起，您的浏览器不支持在线咨询，请更换浏览器');
        }
    });
    
    var sendmsg=function(e){
    	var nowdate=new Date();
    	var sendmsg=$("#usersendmsg").val();
    	if(sendmsg==""){
    		alert("请输入内容");
    	}else{
    		$("#usersendmsg").val("");
    		$(".GJshowmes").append("<div class='media'><a class='media-left' href='#'><img style='width:25px;height:25px' class='media-object' src='https://qiniu.cornergj.top/niceNannysmall.png'></a><div class='media-body'><div> 游客<small class='chat-date'>"+p(nowdate.getHours())+":"+p(nowdate.getMinutes())+"</small></div></br></div><div class='chat-message-user'>"+sendmsg+"</div></div>");
        	$(".GJshowmes").animate({scrollTop:($(".GJshowmes").height()+$(".GJshowmes").scrollTop())+'px'},500);
        	userwebsocket.send(sendmsg);
    	}
    };
    
    //将消息显示在网页上
    function setMessageInnerHTML(innerHTML){
    	var nowdate=new Date();
    	$(".GJshowmes").append("<div class='media'><div class='media-body'><div class='author-name-admin'><small class='chat-date'>"+p(nowdate.getHours())+":"+p(nowdate.getMinutes())+"</small>客服</div></br></div><a class='media-left' href='#'><img style='width:25px;height:25px' class='media-object' src='https://qiniu.cornergj.top/kefu.jpg'></a><div class='chat-message-admin'>"+innerHTML+"</br></div></div>");
    	$(".GJshowmes").animate({scrollTop:($(".GJshowmes").height()+$(".GJshowmes").scrollTop())+'px'},500);
    }
     
    //关闭连接
    function closeWebSocket(){
        userwebsocket.close();
    }
    
    
    